for cc=1:length(place)
    
     aggregate_export_creation_rate_vec.(place{cc}) = 0;
     aggregate_export_destruction_rate_vec.(place{cc}) = 0;
     
     export_creation_rate_bydecile_mat.(place{cc}) = [];
     export_destruction_rate_bydecile_mat.(place{cc}) = [];
     
     one_year_category_exit_rate_vec.(place{cc}) = [];
     one_year_category_exit_rate_bottom_50_vec.(place{cc}) = [];
     
     total_exporting_categories_vec.(place{cc}) = [];
     export_category_75_25_ratio_vec.(place{cc}) = [];
     export_category_90_10_ratio_vec.(place{cc}) = [];
     
     gross_export_creation_contracting_categories_5yr_vec.(place{cc}) = [];
     gross_export_destruction_contracting_categories_5yr_vec.(place{cc}) = [];
     gross_export_creation_expanding_categories_5yr_vec.(place{cc}) = [];
     gross_export_destruction_expanding_categories_5yr_vec.(place{cc}) = [];
        
     for yr = max_year-146:max_year-1
          base_yr_index=['y' num2str(yr)];
          yr_index_lag = ['y' num2str(yr-1)];
          yr_index_5yr_lag = ['y' num2str(yr-5)];
              
     total_exports_category.(place{cc}).(base_yr_index) = grpstats(exports.(place{cc}).(base_yr_index),export_category_index_vec,'sum');
     total_exports_category.(place{cc}).(yr_index_lag) = grpstats(exports.(place{cc}).(yr_index_lag),export_category_index_vec,'sum');
     total_exports_category.(place{cc}).(yr_index_5yr_lag) = grpstats(exports.(place{cc}).(yr_index_5yr_lag),export_category_index_vec,'sum');
     change_exports_category.(place{cc}).(base_yr_index) = total_exports_category.(place{cc}).(base_yr_index)-total_exports_category.(place{cc}).(yr_index_5yr_lag);
     creation_exports_category.(place{cc}).(base_yr_index) = change_exports_category.(place{cc}).(base_yr_index);
     creation_exports_category.(place{cc}).(base_yr_index)(creation_exports_category.(place{cc}).(base_yr_index)<0) = 0;
     destruction_exports_category.(place{cc}).(base_yr_index) = change_exports_category.(place{cc}).(base_yr_index);
     destruction_exports_category.(place{cc}).(base_yr_index)(destruction_exports_category.(place{cc}).(base_yr_index)>0) = 0;

     aggregate_export_creation_rate.(place{cc}).(base_yr_index) = sum(creation_exports_category.(place{cc}).(base_yr_index))/sum(total_exports_category.(place{cc}).(yr_index_5yr_lag));
     aggregate_export_destruction_rate.(place{cc}).(base_yr_index) = -sum(destruction_exports_category.(place{cc}).(base_yr_index))/sum(total_exports_category.(place{cc}).(yr_index_5yr_lag));
     
     gross_created_exports_category_5yr.(place{cc}).(base_yr_index) = grpstats(exports.(place{cc}).(base_yr_index) & ~exports.(place{cc}).(yr_index_5yr_lag),export_category_index_vec,'sum');
     gross_destroyed_exports_category_5yr.(place{cc}).(base_yr_index) = grpstats(~exports.(place{cc}).(base_yr_index) & exports.(place{cc}).(yr_index_5yr_lag),export_category_index_vec,'sum');
    
     gross_export_creation_contracting_categories_5yr_vec.(place{cc}) = [gross_export_creation_contracting_categories_5yr_vec.(place{cc}); ...
                                                    sum(gross_created_exports_category_5yr.(place{cc}).(base_yr_index)(change_exports_category.(place{cc}).(base_yr_index)<0)) / sum(total_exports_category.(place{cc}).(yr_index_5yr_lag))];                  
     gross_export_destruction_contracting_categories_5yr_vec.(place{cc}) = [gross_export_destruction_contracting_categories_5yr_vec.(place{cc}); ...
                                                    sum(gross_destroyed_exports_category_5yr.(place{cc}).(base_yr_index)(change_exports_category.(place{cc}).(base_yr_index)<0)) / sum(total_exports_category.(place{cc}).(yr_index_5yr_lag))];     
     gross_export_creation_expanding_categories_5yr_vec.(place{cc}) = [gross_export_creation_expanding_categories_5yr_vec.(place{cc}); ...
                                                    sum(gross_created_exports_category_5yr.(place{cc}).(base_yr_index)(change_exports_category.(place{cc}).(base_yr_index)>0)) / sum(total_exports_category.(place{cc}).(yr_index_5yr_lag))];    
     gross_export_destruction_expanding_categories_5yr_vec.(place{cc}) = [gross_export_destruction_expanding_categories_5yr_vec.(place{cc}); ...
                                                sum(gross_destroyed_exports_category_5yr.(place{cc}).(base_yr_index)(change_exports_category.(place{cc}).(base_yr_index)>0)) / sum(total_exports_category.(place{cc}).(yr_index_5yr_lag))]; 
  
     total_exporting_categories.(place{cc}).(base_yr_index) = sum(total_exports_category.(place{cc}).(base_yr_index)>0);
     total_exporting_categories_vec.(place{cc}) = [total_exporting_categories_vec.(place{cc}); total_exporting_categories.(place{cc}).(base_yr_index)];
     
     export_category_75_25_ratio.(place{cc}).(base_yr_index) = prctile(total_exports_category.(place{cc}).(base_yr_index)(total_exports_category.(place{cc}).(base_yr_index)>0),75)...
                    /prctile(total_exports_category.(place{cc}).(base_yr_index)(total_exports_category.(place{cc}).(base_yr_index)>0),25);
     export_category_75_25_ratio_vec.(place{cc}) = [export_category_90_10_ratio_vec.(place{cc}); export_category_75_25_ratio.(place{cc}).(base_yr_index)];
     
     export_category_90_10_ratio.(place{cc}).(base_yr_index) = prctile(total_exports_category.(place{cc}).(base_yr_index)(total_exports_category.(place{cc}).(base_yr_index)>0),90)...
                    /prctile(total_exports_category.(place{cc}).(base_yr_index)(total_exports_category.(place{cc}).(base_yr_index)>0),10);
     export_category_90_10_ratio_vec.(place{cc}) = [export_category_90_10_ratio_vec.(place{cc}); export_category_90_10_ratio.(place{cc}).(base_yr_index)];
     
     
     %%% CATEGORY EXIT RATES
     one_year_category_exit_rate.(place{cc}).(base_yr_index) = sum(logical(total_exports_category.(place{cc}).(base_yr_index)==0&~total_exports_category.(place{cc}).(yr_index_lag)==0)) ...
                    ./(sum(logical(~total_exports_category.(place{cc}).(yr_index_lag)==0)));
     median_category_exports.(place{cc}) = median(total_exports_category.(place{cc}).(yr_index_lag)(total_exports_category.(place{cc}).(yr_index_lag)>0));
     one_year_category_exit_rate_bottom_50.(place{cc}).(base_yr_index) = sum(logical(total_exports_category.(place{cc}).(base_yr_index)==0 ...
                    &~total_exports_category.(place{cc}).(yr_index_lag)==0 & ...
                    total_exports_category.(place{cc}).(yr_index_lag)<median_category_exports.(place{cc}))) ...
                    ./(sum(logical(~total_exports_category.(place{cc}).(yr_index_lag)==0 & ...
                    total_exports_category.(place{cc}).(yr_index_lag)<median_category_exports.(place{cc}))));
                
     one_year_category_exit_rate_vec.(place{cc}) = [one_year_category_exit_rate_vec.(place{cc}); one_year_category_exit_rate.(place{cc}).(base_yr_index)];
     one_year_category_exit_rate_bottom_50_vec.(place{cc}) = [one_year_category_exit_rate_bottom_50_vec.(place{cc}); one_year_category_exit_rate_bottom_50.(place{cc}).(base_yr_index)];
     
     
    %%% ORGANIZE DECILES AND CALCULATE AGGREGATE CREATION/DESTRUCTION
    define_deciles.(place{cc}).(base_yr_index) = prctile(total_exports_category.(place{cc}).(yr_index_5yr_lag)(total_exports_category.(place{cc}).(yr_index_5yr_lag)>0)...
                                            ,[0 10 20 30 40 50 60 70 80 90 100]);                                    
    exports_decile_lastperiod.(place{cc}).(base_yr_index) = discretize(total_exports_category.(place{cc}).(yr_index_5yr_lag),define_deciles.(place{cc}).(base_yr_index));
    exports_decile_lastperiod.(place{cc}).(base_yr_index)(total_exports_category.(place{cc}).(yr_index_5yr_lag)==0) = NaN;
    
    total_exports_decile.(place{cc}).(yr_index_5yr_lag) = grpstats(total_exports_category.(place{cc}).(yr_index_5yr_lag),exports_decile_lastperiod.(place{cc}).(base_yr_index),'sum');
    creation_exports_decile.(place{cc}).(base_yr_index) = grpstats(creation_exports_category.(place{cc}).(base_yr_index),exports_decile_lastperiod.(place{cc}).(base_yr_index),'sum');
    destruction_exports_decile.(place{cc}).(base_yr_index) = grpstats(destruction_exports_category.(place{cc}).(base_yr_index),exports_decile_lastperiod.(place{cc}).(base_yr_index),'sum');

    export_creation_rate_bydecile.(place{cc}).(base_yr_index) = creation_exports_decile.(place{cc}).(base_yr_index)./total_exports_decile.(place{cc}).(yr_index_5yr_lag);
    export_destruction_rate_bydecile.(place{cc}).(base_yr_index) = -destruction_exports_decile.(place{cc}).(base_yr_index)./total_exports_decile.(place{cc}).(yr_index_5yr_lag);
    
    aggregate_export_creation_rate_vec.(place{cc}) = [aggregate_export_creation_rate_vec.(place{cc}); aggregate_export_creation_rate.(place{cc}).(base_yr_index)];
    aggregate_export_destruction_rate_vec.(place{cc}) = [aggregate_export_destruction_rate_vec.(place{cc}); aggregate_export_destruction_rate.(place{cc}).(base_yr_index)];
    
    if length(export_creation_rate_bydecile.(place{cc}).(base_yr_index))==10
    export_creation_rate_bydecile_mat.(place{cc}) = [export_creation_rate_bydecile_mat.(place{cc}) export_creation_rate_bydecile.(place{cc}).(base_yr_index)];
    export_destruction_rate_bydecile_mat.(place{cc}) = [export_destruction_rate_bydecile_mat.(place{cc}) export_destruction_rate_bydecile.(place{cc}).(base_yr_index)];
    end
    
    end
    
     if size(export_creation_rate_bydecile_mat.(place{cc}),2) > 25
     export_creation_rate_bydecile_avg.(place{cc}) = mean(export_creation_rate_bydecile_mat.(place{cc})(:,end-99:end),2);
     export_destruction_rate_bydecile_avg.(place{cc}) = mean(export_destruction_rate_bydecile_mat.(place{cc})(:,end-99:end),2);
     difference_destruction_largest_smallest_decile.(place{cc}) = export_destruction_rate_bydecile_avg.(place{cc})(end)-export_destruction_rate_bydecile_avg.(place{cc})(1);
     else
     difference_destruction_largest_smallest_decile.(place{cc}) = export_destruction_rate_bydecile.(place{cc}).(base_yr_index)(end)-export_destruction_rate_bydecile.(place{cc}).(base_yr_index)(1);
     end
     
     aggregate_export_creation_rate_avg.(place{cc}) = mean(aggregate_export_creation_rate_vec.(place{cc})(end-99:end));
     aggregate_export_destruction_rate_avg.(place{cc}) = mean(aggregate_export_destruction_rate_vec.(place{cc})(end-99:end));
     
     category_exit_rate_avg.(place{cc}) = mean(one_year_category_exit_rate_vec.(place{cc})(end-99:end));
     category_exit_rate_bottom_50_avg.(place{cc}) = mean(one_year_category_exit_rate_bottom_50_vec.(place{cc})(end-99:end));
     
     total_exporting_categories_avg.(place{cc}) = mean(total_exporting_categories_vec.(place{cc})(end-99:end));
     export_category_75_25_ratio_avg.(place{cc}) = mean(export_category_75_25_ratio_vec.(place{cc})(end-99:end));
     export_category_90_10_ratio_avg.(place{cc}) = mean(export_category_90_10_ratio_vec.(place{cc})(end-99:end));
     
     gross_export_creation_contracting_categories_5yr_avg.(place{cc}) = mean(gross_export_creation_contracting_categories_5yr_vec.(place{cc})(end-99:end));
     gross_export_destruction_contracting_categories_5yr_avg.(place{cc}) = mean(gross_export_destruction_contracting_categories_5yr_vec.(place{cc})(end-99:end));
     gross_export_creation_expanding_categories_5yr_avg.(place{cc}) = mean(gross_export_creation_expanding_categories_5yr_vec.(place{cc})(end-99:end));
     gross_export_destruction_expanding_categories_5yr_avg.(place{cc}) = mean(gross_export_destruction_expanding_categories_5yr_vec.(place{cc})(end-99:end));
     
end

